// pages/ScenicArea/NianCardOrder/Cardcomment/Cardcomment.js
var common = require("../../../../public.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        flag: -1,
        value: 0,
        comentList: [
            {
                imgNone: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/icon/coment_threeActive.png',
                imgActive: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/icon/coment_three.png',
                text: '超赞'
            },


            {
                imgNone: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/icon/coment_twoActive.png',
                imgActive: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/icon/coment_two.png',
                text: '一般'
            },
            {
                imgNone: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/icon/coment_oneActive.png',
                imgActive: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/icon/coment_one.png',
                text: '非常差'
            },

        ],
        imgActive: 0,
        textActive: 0,
        commentThree: [],
        commentTwo: [],
        commentOne: [
            // {name:'价格一般'},
            // {name:"等待时间长"},
            // {name:'优惠多'},
            // {name:'价格一般'},
            // {name:"等待时间长"},
            // {name:'优惠多'},
        ],
        storeId: ''
    },

    click_text(e) {
        let index = e.currentTarget.dataset.index
        let item = e.currentTarget.dataset.item

        this.data.commentOne[index].isSelect = !item.isSelect
        this.setData({
            commentOne: this.data.commentOne
        }, () => {

        })
    },
    click_texts(e) {
        let index = e.currentTarget.dataset.index
        let item = e.currentTarget.dataset.item

        this.data.commentTwo[index].isSelect = !item.isSelect
        let arr = []

        this.setData({
            commentTwo: this.data.commentTwo
        }, () => {
            // console.log(this.data.commentTwo[index])
            // if(item.isSelect){

            // }
            // arr.push()
        })
    },
    click_textss(e) {
        let index = e.currentTarget.dataset.index
        let item = e.currentTarget.dataset.item

        this.data.commentThree[index].isSelect = !item.isSelect
        this.setData({
            commentThree: this.data.commentThree
        })
    },
    goBack() {
        const pages = getCurrentPages();
        const prevPage = pages[pages.length - 2]; //上一个页面
        // 从朋友圈进入的时候，页面栈为空，这里需要判断是否有上个页面
        if (prevPage) {
            wx.navigateBack({
                delta: 1
            })
        }
    },
    click_coment(e) {
        console.log(e.currentTarget.dataset.index, "444444555")
        let index = e.currentTarget.dataset.index
        this.setData({
            imgActive: index
        }, () => {
            this.click_submit()
        })
    },
    click_submit() {
        // 满意度 1超赞 2一般 3非常差
        console.log()
        const that = this
        let temp = {
            storeId: this.data.storeId,
            // storeId: 14,
            level: this.data.imgActive + 1
        }
        common.post('/order/selectAssessTag', temp, function (res) {
            if (res.status === 200) {

                for (let i = 0; i < res.data.length; i++) {
                    res.data[i].isSelect = false
                }
                if (that.data.imgActive == 0) {
                    that.setData({
                        commentOne: res.data
                    })
                } else if (that.data.imgActive == 1) {

                    that.setData({
                        commentTwo: res.data
                    })

                } else {
                    if (that.data.imgActive == 2) {
                        that.setData({
                            commentThree: res.data
                        })
                    }
                }
            } else {
                common.showRequestErrMsg(res)
            }
        })

    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const that = this
        //获取胶囊位置
        let capsule = wx.getMenuButtonBoundingClientRect()
        this.setData({
            height: capsule.height,
            top: capsule.top,
        })
        console.log(options, "55555555")
        wx.getStorage({
            key: 'user',
            success: function (res) {
                that.setData({
                    userInfo: res.data.user,
                    token: res.data.token,
                    openid: res.data.openid,
                    storeId: options.storeId,
                    orderNo: options.orderNo,
                    flag: options.flag   //0门票 1是商品
                }, () => {
                    // that.initData();
                    that.click_submit()
                    console.log(that.data.orderobj, "555144555")
                })
            }
        })
    },
    // 订单详情
    initData() {
        const that = this
        let tempJson = {
            userId: that.data.userInfo.id,
            token: that.data.token,
            orderNo: that.data.orderNo,
        }
        this.setData({
            isLoading: true
        })
        common.post('/ticketOrder/getMyTicketOrderDetail', tempJson, function (res) {
            if (res.status === 200) {
                that.setData({
                    scenicTicket: res.data.scenicTicket,
                    storeInfo: res.data.store,
                    ticketOrder: res.data.ticketOrder,
                    ticketTime: res.data.ticketTime
                })
            } else {
                common.showRequestErrMsg(res)
            }
        }, function () {
            that.setData({
                isLoading: false
            })
        })
    },
    // 提交评价
    sub_comment() {
        const that = this
        let tagIds = [];
        if (this.data.imgActive == 0) {
            this.data.commentOne.map((item, index) => {
                if (item.isSelect) {
                    tagIds.push(item.id)
                }

            })
        } else if (this.data.imgActive == 1) {
            this.data.commentTwo.map((item, index) => {
                if (item.isSelect) {
                    tagIds.push(item.id)
                }

            })
        } else {
            this.data.commentThree.map((item, index) => {
                if (item.isSelect) {
                    tagIds.push(item.id)
                }

            })
        }

        console.log(tagIds, "ooooooooooo")
        // if (tagIds.length == 0 || !tagIds) {
        //     wx.showToast({
        //         title: '请选择评价',
        //         icon: 'none'
        //     })
        //     return
        // }
        if (tagIds.length == 0) {
            tagIds = ''
        }
        let tempJson = {
            userId: that.data.userInfo.id,
            // score: that.data.value,
            tagIds: tagIds,
            orderNo: that.data.orderNo,
            token: that.data.token
        }
        this.setData({
            isLoading: true
        })

        let url;
        if (that.data.flag == 0) {
            url = '/ticketOrder/insertTicketAssess' 
        } else if (that.data.flag == 1) {
            url = '/order/insertItemsAssess'
        }
        common.post(url, tempJson, function (res) {
            if (res.status === 200) {
                common.showToast(res.msg)
                wx.navigateTo({
                    url: '/pages/ScenicArea/NianCardOrder/index',
                })
            } else {
                common.showRequestErrMsg(res)
            }
        })
    },
    // 几颗星星
    onChange(event) {
        this.setData({
            value: event.detail,
        });
    },

})